package xyz.ddlnt.user.usr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.commonutil.util.HttpUtils;
import xyz.ddlnt.model.dto.PostCommentAreaDTO;
import xyz.ddlnt.model.dto.PostCommentDTO;
import xyz.ddlnt.model.vo.MyCommentVO;
import xyz.ddlnt.model.vo.PostCommentVO;
import xyz.ddlnt.model.vo.ReplyCommentVO;
import xyz.ddlnt.serviceusrclient.client.PostCommentFeignClient;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/27 23:08
 */
@Slf4j
@Tag(name = "帖子评论接口测试")
@RequestMapping("/post_comment")
@RestController
public class PostCommentController {
    @Resource
    private PostCommentFeignClient postCommentFeignClient;

    @Operation(summary = "保存帖子评论")
    @PostMapping("/save")
    Result<Boolean> savePostComment(@RequestBody PostCommentDTO postCommentDTO, HttpServletRequest request) {
        postCommentDTO.setUserId(HttpUtils.getId(request));
        return postCommentFeignClient.savePostComment(postCommentDTO);
    }

    @Operation(summary = "获取帖子评论")
    @PostMapping("/getPostComment")
    Result<List<PostCommentVO>> getPostComment(@RequestBody PostCommentAreaDTO postCommentAreaDTO) {
        return postCommentFeignClient.getPostComment(postCommentAreaDTO);
    }


    @Operation(summary = "获取用户评论")
    @GetMapping("/getMyComment/{id}")
    Result<List<MyCommentVO>> getMyComment(@PathVariable Long id, HttpServletRequest request) {
        return id == 0? postCommentFeignClient.getMyComment(HttpUtils.getId(request)) : postCommentFeignClient.getMyComment(id);
    }

    @Operation(summary = "获取用户回复")
    @GetMapping("/getReplyComment")
    Result<List<ReplyCommentVO>> getReplyComment(HttpServletRequest request) {
        return postCommentFeignClient.getReplyComment(HttpUtils.getId(request));
    }
}
